import { createRouter, createWebHistory } from 'vue-router'
import NProgress from '@/config/nprogress.js'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      component: () => import('@/views/index/index.vue'),
      redirect: '/login',
      children: [
        {
          path: '/login',
          name: 'login',
          component: () => import('@/views/login/index.vue'),
        },
        {
          path: '/register',
          name: 'register',
          component: () => import('@/views/register/index.vue'),
        },
      ]

    },
    {
      path: '/home',
      name: 'home',
      component: () => import('@/views/home/index.vue'),
      redirect: '/home/index',
      children: [
        {
          path: 'index',
          name: 'home-index',
          component: () => import('@/views/main/index.vue'),
        },
        {
          path: 'menu/:id',
          props:true,
          name: 'home-menu',
          component: () => import('@/views/menu/index.vue'),
        },
        {
          path: 'cart',
          name: 'home-cart',
          component: () => import('@/views/cart/index.vue'),
        },
        {
          path: 'mine',
          name: 'home-mine',
          component: () => import('@/views/mine/index.vue'),
        },
      ],
    },
    {
      path:'/center',
      name:'center',
      component:()=>import('@/views/center/index.vue')
    },
    {
      path:'/password',
      name:'password',
      component:()=>import('@/views/password/index.vue')
    },
    {
      path:'/charge',
      name:'charge',
      component:()=>import('@/views/charge/index.vue')
    },
    {
      path:'/notice',
      name:'notice',
      component:()=>import('@/views/notice/index.vue')
    },
    {
      path:'/activity',
      name:'activity',
      component:()=>import('@/views/activity/index.vue')
    },
    {
      path:'/shop',
      name:'shop',
      component:()=>import('@/views/shop/index.vue')
    },
    {
      path:'/product/:id',
      name:'product',
      props:true,
      component:()=>import('@/views/product-detail/index.vue')
    },
    {
      path:'/order/:id',
      name:'order',
      props:true,
      component:()=>import('@/views/order/index.vue')
    },
    {
      path:'/order/detail/:id',
      name:'order-detail',
      props:true,
      component:()=>import('@/views/order-detail/index.vue')
    }
  ],
})

router.beforeEach((to, from, next) => {
  NProgress.start()
  next()
})

router.afterEach(() => {
  NProgress.done()
})

export default router
